module.exports = (options, app) => {
    return async (ctx, next) => {
      const xForwardedFor = ctx.request.header['x-forwarded-for'];
      
      const clientIp = xForwardedFor ? xForwardedFor.split(',')[0] : ctx.request.header['remote-addr'] || ctx.request.header['x-real-ip'] || ctx.socket.remoteAddress
  
      ctx.state.clientIp = clientIp
      await next()
    };
  };